package com.googlecode.bpmcenter.model;
 
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
 
@Entity
@Table(name="BPM_FOLDER")
public class Folder {
 
    private Long id;
    private String name;
    private Folder parent;
    private List<Folder> subFolders;
    private List<File> files;
 
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "ID")
    public Long getId() {
        return id;
    }
 
    public void setId(Long id) {
        this.id = id;
    }
 
    @Column(name="NAME")
    public String getName() {
        return name;
    }
 
    public void setName(String name) {
        this.name = name;
    }
 
    @ManyToOne
    @JoinColumn(name="PARENT_FOLDER")
		public Folder getParent() {
    	return parent;
    }

		public void setParent(Folder parent) {
    	this.parent = parent;
    }

		@OneToMany(targetEntity=Folder.class, mappedBy = "parent")
		public List<Folder> getSubFolders() {
    	return subFolders;
    }

		public void setSubFolders(List<Folder> subFolders) {
    	this.subFolders = subFolders;
    }

		@OneToMany(targetEntity = File.class, mappedBy = "folder", fetch = FetchType.EAGER)
		public List<File> getFiles() {
    	return files;
    }

		public void setFiles(List<File> files) {
    	this.files = files;
    }
		
    @Override
    public String toString() {
        StringBuffer strBuff = new StringBuffer();
        strBuff.append("id : ").append(getId());
        strBuff.append(", name : ").append(getName());
        return strBuff.toString();
    }

}